package cn.edu.neusoft.yuejian12.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.yuejian12.Activity.ClubInfoActivity;
import cn.edu.neusoft.yuejian12.Activity.TrainInfoActivity;
import cn.edu.neusoft.yuejian12.JavaBean.Club;
import cn.edu.neusoft.yuejian12.JavaBean.Train;
import cn.edu.neusoft.yuejian12.R;

/**
 * Created by 木子李 on 2017/10/12.
 */

public class ClubAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;
    private List mDataList;//数据存储


    private LayoutInflater mLayoutInflater;//准备布局
    public ClubAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.clubcardview, parent, false);
        return new ClubAdapter.ViewHolder(v);

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Club entity = (Club) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.clubHname.setText(entity.getClub_name());
        String address="http://172.24.10.175/workout/Uploads/"+entity.getThumb();
        if(!entity.getThumb().equals("")){
            Picasso.with(mContext).load(address).into(viewHolder.clubHthumb);
        }
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,ClubInfoActivity.class);
                intent.putExtra("club_id",entity.getId());
                intent.putExtra("club_name",entity.getClub_name());
                intent.putExtra("club_photo",entity.getThumb());
                mContext.startActivity(intent);
            }
        });





       /* viewHolder.bar.setNumStars(5);
        viewHolder.bar.setRating((int)entity.get("ratingBar2"));
        viewHolder.news_thumb.setImageResource(Integer.parseInt(entity.get("news_thumb").toString()));*/


    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView clubHthumb;
        TextView clubHname;
        LinearLayout linearLayout;



        public ViewHolder(View itemView) {
            super(itemView);
            linearLayout = (LinearLayout) itemView.findViewById(R.id.club_container);
            clubHname = (TextView) itemView.findViewById(R.id.clubHname);

            clubHthumb = (ImageView) itemView.findViewById(R.id.clubHthumb);


        }
    }

}
